import "./public-path";
import React from "react";
import ReactDOM from "react-dom/client";
import { BrowserRouter } from "react-router-dom";
import App from "./App";

let root;

function render(props) {
  const container = props.container
    ? props.container.querySelector("#root")
    : document.getElementById("root");

  root = ReactDOM.createRoot(container);
  root.render(
    <React.StrictMode>
      <BrowserRouter
        basename={window.__POWERED_BY_QIANKUN__ ? "/react18" : "/"}
      >
        <App />
      </BrowserRouter>
    </React.StrictMode>
  );
}

if (!window.__POWERED_BY_QIANKUN__) {
  render({});
}

export async function bootstrap() {}

export async function mount(props) {
  render(props);
}

export async function unmount() {
  root.unmount();
}
